package ymlTest

import (
	"errors"
	"fmt"
	"github.com/spf13/viper"
)

type ConfModel interface {
	Err(err error) string
}

type Base struct {
}

func (Base) Err(err error) string {
	return err.Error()
}

func ReadYmlByViper(cfgPtr ConfModel, filePaths ...string) (err error) {
	if len(filePaths) == 0 {
		err = errors.New("nil file")
		return
	}
	for _, path := range filePaths {
		viper.SetConfigFile(path)
		err = viper.MergeInConfig()
		if err != nil {
			err = fmt.Errorf("config file path %s err %s", path, err)
			return
		}
	}
	err = viper.Unmarshal(cfgPtr)
	return
}

type configModel struct {
	Base
	Db Mysql
}

type Mysql struct {
	Host               string
	Port               uint16
	DbName             string
	UserName           string
	Password           string
	Debug              bool
	MaxIdleConnections int
	MaxOpenConnections int
}
